package com.guslegend.spzx.manager.service.Impl;


import com.guslegend.spzx.manager.service.SysRoleUserService;
import com.guslegend.spzx.model.dto.system.AssginRoleDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.guslegend.spzx.manager.mapper.SysRoleUserMapper;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: guslegend
 * @description:
 * @create: 2025-05-09 07:41
 **/
@Service
public class SysRoleUserServiceImpl implements SysRoleUserService {

    @Autowired
    private SysRoleUserMapper sysRoleUserMapper ;

    @Transactional
    @Override
    public void doAssign(AssginRoleDto assginRoleDto) {

        // 删除之前的所有的用户所对应的角色数据
        sysRoleUserMapper.deleteByUserId(assginRoleDto.getUserId()) ;

        // 分配新的角色数据
        List<Long> roleIdList = assginRoleDto.getRoleIdList();
        roleIdList.forEach(roleId->{
            sysRoleUserMapper.doAssign(assginRoleDto.getUserId(),roleId);
        });
    }
}
